package TUILayer;
import java.util.Scanner;
import ControllerLayer.*;

public class LoginUI
{
    private UserController userController;
    
    public static void main(String[]args){
        new LoginUI().selectMenu();
    }
    
   
    
    private int MainMenu()
    {  
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** Login Menu ***");
            System.out.println(" (1) Log In");
            System.out.println(" (2) exit");
            System.out.print("\n Make your choice: ");
            
            int choise = keyboard.nextInt();
            
            return choise;
    }
    private void selectMenu(){
       userController= new UserController();
        boolean exit = false;
       while(!exit)
       {
          int choise = MainMenu(); 
          if(choise == 1)
          {   
              login();
          }
          
                        else{
                             exit = true;
                        }
                        }
    }
    
    
    
    private void login()
    {
        String id=inputID();
        if(userController.findUser(id)!=null)
        {
            String password=inputPassword();
            if(userController.findUser(id).getPassword().equals(password))
            {
                if(userController.findUser(id).isManager())
                {
                    new MainIIUI();
                }
                else
                {
                    new MainUI(id);
                }
            }
        }
        
    }
        private String  inputID()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type  ID: ");
        String address = keyboard.nextLine();
        return address;
    }
    
    
    private String  inputPassword()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type password: ");
        String address = keyboard.nextLine();
        return address;
    }
    
}